package com.ta.gulimall.product.controller;

import java.util.Arrays;
import java.util.List;

import com.ta.gulimall.product.view.vo.BrandVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import com.ta.gulimall.product.view.entity.CategoryBrandRelationEntity;
import com.ta.gulimall.product.service.CategoryBrandRelationService;
import com.ta.gulimall.common.utils.system.R;



/**
 * 品牌分类关联
 *
 * @author tuao
 * @email tuaoo@gmail.com
 * @date 2022-10-29 01:29:17
 */
@RestController
@RequestMapping("product/categorybrandrelation")
public class CategoryBrandRelationController {
    @Autowired
    private CategoryBrandRelationService categoryBrandRelationService;

    /**
     * 查询品牌下的分类集合
     */
    @RequestMapping("/catelog/list")
    public R list(Long brandId){
        List<CategoryBrandRelationEntity> data = categoryBrandRelationService.getCategoryBrandRelations(brandId);

        return R.ok().put("data", data);
    }

    /**
     * 分类下的品牌信息集合
     * @param catId
     * @return
     */
    @GetMapping("/brands/list")
    public R brandsList(Long catId){
        List<BrandVo> brandVos = categoryBrandRelationService.getBrandVos(catId);

        return R.ok().put("data", brandVos);
    }

    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    public R info(@PathVariable("id") Long id){
		CategoryBrandRelationEntity categoryBrandRelation = categoryBrandRelationService.getById(id);

        return R.ok().put("categoryBrandRelation", categoryBrandRelation);
    }

    /**
     * 保存品牌下的分类信息
     */
    @RequestMapping("/save")
    public R save(@RequestBody CategoryBrandRelationEntity categoryBrandRelation){
		categoryBrandRelationService.saveCategoryBrandRelation(categoryBrandRelation);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    public R update(@RequestBody CategoryBrandRelationEntity categoryBrandRelation){
		categoryBrandRelationService.updateById(categoryBrandRelation);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    public R delete(@RequestBody Long[] ids){
		categoryBrandRelationService.removeByIds(Arrays.asList(ids));

        return R.ok();
    }

}
